﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using QuickCode.Application;
using QuickCode.Application.DTO;
using QuickCode.IApplication;
using Util;

namespace QuickCode.WebApi.Controllers
{
    /// <summary>
    /// 用户接口
    /// </summary>
    [Route("Api/User")]
    [ApiExplorerSettings(GroupName = "User")]
    //[Authorize]
    public class UserController: BaseController
    {
        private IUserApplication _user;
        /// <summary>
        /// user
        /// </summary>
        /// <param name="user"></param>
        public UserController(IUserApplication user)
        {
            _user=user;
        }
        /// <summary>
        /// 获取第一个用户名称
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetFirstUserName")]
        public string GetFirstUserName()
        {
            return _user.GetFirstUserName();
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddUser")]
        public WebApiPackage<bool> AddUser(UserDTO user)
        {
            return Data<bool>(_user.AddUser(user));
        }

        /// <summary>
        /// 获取用户
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        [HttpPost("GetUsers")]
        public WebApiPackageList<UserDTO> GetUsers(Pagination page)
        {
            return List(_user.GetUsers(), page);
        }

        /// <summary>
        /// 设置用户缓存
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        [HttpPost("SetUserCache")]
        public WebApiPackage<string> SetUserCache(string userName)
        {
            return Data<string>(_user.SetUserCache(userName));
        }

        /// <summary>
        /// SQL Sugar 创建表（Codefirst）
        /// </summary>
        /// <returns></returns>
        [HttpPost("CreateTable")]
        public WebApiPackage<bool> CreateTable()
        {
            return Data<bool>(_user.CreateTable());
        }

        /// <summary>
        /// SQL Sugar 创建实体（DBfirst）
        /// </summary>
        /// <returns></returns>
        [HttpPost("CreateEntity")]
        public WebApiPackage<bool> CreateEntity()
        {
            return Data<bool>(_user.CreateEntity());
        }
    }
}
